home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
machack
/
Hacks97
/
WarriorsProgress.sit
/
Warrior’s Progress
/
source code
/
Source
/
Libraries
/
Events
/
EventQueue.cp
< prev
next >
Wrap
Text File
|
1997-06-28
|
2KB
|
98 lines
// EventQueue.cp
#ifndef EventQueue_h
#include "EventQueue.h"
#endif
EventQueue& EventQueue::The()
{
static EventQueue the;
return the;
}
EventQueue::EventQueue()
: previous( 0 ),
current( 0 ),
next( 0 )
{
}
void EventQueue::Advance()
{
if ( previous != 0 )
events.Delete( previous );
previous = current;
current = next;
next = 0;
if ( current != 0 && !Valid( *current ) )
{
events.Delete( current );
current = 0;
}
}
void EventQueue::operator++()
{
Advance();
if ( current == 0 )
{
current = new(events) EventRecord;
Assert( current != 0 );
WaitNextEvent( everyEvent, current, 0, 0 );
}
}
void EventQueue::AdvanceWithoutWaiting()
{
Advance();
if ( current == 0 )
{
current = new(events) EventRecord;
Assert( current != 0 );
WaitNextEvent( everyEvent, current, 0, 0 );
}
}
void EventQueue::operator--()
{
Assert( previous != 0 );
Assert( current != 0 );
Assert( next == 0 );
next = current;
current = previous;
previous = 0;
}
bool EventQueue::Valid( const EventRecord& event )
{
switch( event.what )
{
case nullEvent:
return false;
case activateEvt:
case updateEvt:
return Exists( reinterpret_cast<WindowPeek>( event.message ) );
}
return true;
}
bool EventQueue::Exists( WindowPeek target )
{
Assert( target != 0 );
for ( WindowPeek window = reinterpret_cast<WindowPeek>( FrontWindow() );
window != 0;
window = window->nextWindow )
if ( window == target )
return true;
return false;
}